package b1.scenes.fight
{
	import Box2D.Collision.*;
	import Box2D.Collision.Shapes.*;
	import Box2D.Common.Math.*;
	import Box2D.Dynamics.Joints.*;
	
	import b1.conifg.*;
	import b1.controls.basic.AnimalMc;
	import b1.controls.basic.BasicMc;
	import b1.net.*;
	import b1.players.*;
	import b1.scenes.*;
	import b1.utils.BFont;
	
	import com.greensock.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.utils.Timer;
	import flash.utils.getDefinitionByName;
	
	public class Animal extends FightObject
	{
		//动物基本信息
		public var animalId:int;
		//动物图片
		public var animalMc:AnimalMc;
		//准备扔的骨头
		private var preparedBoneIndex:int;
		//使用的发射器
		public var launcher:Launcher;
		//动物掉落的线索
		public var animalCluesDrop:Object;
		//boss掉落的装备
		public var bossEquipDrop:Object;
		//消耗的物品列表（包括骨头、道具）
		public var consumedObjects:Object;
		//血量的变化
		public var addHealhPoint:int;
		//体力的变化
		public var addVitalityPoint:int;
		//血条
		private var healthBar:Bar;
		//体力条
		private var vitalityBar:Bar;
		//回合进度条
		public var progressBar:ProgressBar;
		//动物说话
		private var speakMsgBgrSprite:Sprite;
		private var speakMsgText:TextField;
		//左侧或者右侧
		public var leftFlag:Boolean;
		//击晕的最终时间
		public var timeToStopDizzy:int;
		//减慢的最终时间
		public var timeToStopSlow:int;
		//流血计数
		public var bloodDropEffectCoolDown:int;
		//加血计数
		public var bloodGainEffectCoolDown:int;
		//额外流血数
		private var healthPointDrop:int;
		//额外加血数
		private var healthPointGain:int;
		//流血的图片
		private var dropBloodImg:Sprite;
		//冰
		private var iceImg:Sprite;
		//骨牢
		private var cageImg:Sprite;
		//进度条变慢之前的速度
		private var speedBeforeSlow:Number;
		//动物停止的回合计数（骨牢效果）
		public var cageEffectCoolDown:int;
		//动物原来的速度
		private var speedBeforeStop:int;
		//背包物品是否可以点击
		public var animalDizzyMc:BasicMc;
		//是否固定在原地
//		public var stopWalkFlag:Boolean;
		private var walkSpeed:Number;
		//动物信息显示
		private var animalTip:AnimalTip;
		//动物变大小回合数目
		public var changeSizeEffectCoolDown:int;
		//动物隐形回合数目
		public var transparentEffectCoolDown:int;
		//是否正在说话
		public var speakFlag:Boolean;
		//魔法效果
		public var magicMovie:BasicMc;
		//状态集合
		public var allStatus:Object;
		//时钟
		private var timer:Timer;
		private var walkTimer:Timer;
		//召唤动画
		protected var summonMovie:BasicMc;
		//移动目标
		private var moveTarget:int;
		
		public function Animal(animalId:int, leftFlag:Boolean)
		{
			super(leftFlag);
			this.animalId = animalId;
			this.leftFlag = leftFlag;
			this.speakFlag = false;
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			var animalConfig:AnimalConfig = Config.animalConfigs[animalInfo.animalIndex];
			if (this.leftFlag)
			{
				animalMc = new AnimalMc(animalId, animalConfig.heightInFight, 4);
			}
			else
			{
				animalMc = new AnimalMc(animalId, animalConfig.heightInFight, 3);
			}
			addChild(animalMc);
						
			//初始化其他变量
			animalCluesDrop = new Object();
			bossEquipDrop = new Object();
			consumedObjects = new Object();
			//初始化热点
			initialAnimalHitPoints();
			
			this.animalMc.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.animalMc.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			//重置状态
			allStatus = new Object();
			//加载时钟
			timer = new Timer(500);
			timer.start();
			timer.addEventListener(TimerEvent.TIMER, onTick);
			this.walkSpeed = baseWalkSpeed;
			if (this.leftFlag)
			{
				this.moveTarget = 170;
			}
			else 
			{
				this.moveTarget = 460 + Math.random() * 300;
			}
		}
		
		//卸载发射器（弓）
		public function getOffLauncher():void
		{
			if (launcher != null && launcher.parent != null)
			{
				launcher.parent.removeChild(launcher);
				launcher = null;
			}
		}
		
		//加载发射器（弓）
		public function getOnLauncher(launcherIndex:int):void
		{
			var oldPreparedBoneIndex:int = -1;
			if (launcher != null && launcher.preparedBone != null)
				oldPreparedBoneIndex = launcher.preparedBone.index;
			getOffLauncher();
			launcher = new Launcher(launcherIndex);
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			var animalConfig:AnimalConfig = Config.animalConfigs[animalInfo.animalIndex];
			if (this.leftFlag)
			{
				launcher.x = animalConfig.leftXSite;
				launcher.y = animalConfig.leftYSite;
				launcher.rotation = animalConfig.leftRotation;
			}
			else
			{
				launcher.x = -animalConfig.leftXSite;
				launcher.y = animalConfig.leftYSite;
				launcher.rotation = -animalConfig.leftRotation;
			}
			if (oldPreparedBoneIndex != -1)
				launcher.prepareBone(oldPreparedBoneIndex);
			addChild(launcher);
		}
		
		//显示动物信息
		public function onMouseOver(event:MouseEvent):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			animalTip = new AnimalTip(animalInfo, this.leftFlag);
			animalTip.y = - animalTip.height + this.y;
			if (this.leftFlag)
			{
				animalTip.x = this.x + this.width / 2;
			}
			else
			{
				animalTip.x = this.x - this.width / 2 - animalTip.width;
			}
			fight.addChild(animalTip);
		}
		
		//去掉动物信息
		public function onMouseOut(event:MouseEvent):void
		{
			if (null !=  this.animalTip && null != animalTip.parent)
        	{
        		animalTip.parent.removeChild(animalTip);
        	}
		}
		
		//添加生命、体力、回合进度条
		public function addThreeBars(scene:Sprite, orderNum:int, hiddenFlag:Boolean = false):void
		{
			var barWidth:Number = 100;
			var barHeight:Number = 10;
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			//血条
			healthBar = new Bar("BloodButtomBar", "BloodTopBar", animalInfo.healthPointMax, animalInfo.healthPoint, barWidth, barHeight, this.leftFlag, "生命", 0xFF0000);
			//体力
			vitalityBar = new Bar("LifeButtomBar", "LifeTopBar", animalInfo.vitalityPointMax, animalInfo.vitalityPoint, barWidth, barHeight, this.leftFlag, "体力", 0xFFFF00);
			//回合进度条
			progressBar = new ProgressBar(animalInfo.speed, this);
			//设置血量条，体力条，回合进度条的位置
			if (!hiddenFlag)
			{
				//左侧
				if (this.leftFlag)
				{
					healthBar.x = 0;
					vitalityBar.x = 0;
					progressBar.x = 0;
				}
				//右侧
				else
				{
					healthBar.x = 800 - barWidth - (barWidth + 40) * orderNum ;
					vitalityBar.x = 800 - barWidth - (barWidth + 40) * orderNum ;
					progressBar.x = 800 - progressBar.width - (barWidth + 40) * orderNum;
				}
				healthBar.y = 30;
				vitalityBar.y = 65;
				progressBar.y = 110;
				TweenLite.from(healthBar, 1, {delay: 2, y:0, alpha:0});
				TweenLite.from(vitalityBar, 1, {delay: 2, y:0, alpha:0});
				TweenLite.from(progressBar, 1, {delay: 2, y:0, alpha:0});
				healthBar.addEventListener(MouseEvent.MOUSE_OVER, healthBar.onMouseOver);
				healthBar.addEventListener(MouseEvent.MOUSE_OUT, healthBar.onMouseOut);
				vitalityBar.addEventListener(MouseEvent.MOUSE_OVER, vitalityBar.onMouseOver);
				vitalityBar.addEventListener(MouseEvent.MOUSE_OUT, vitalityBar.onMouseOut);
				scene.addChild(healthBar);
				scene.addChild(vitalityBar);
				scene.addChild(progressBar);
			}
		}
		
		private function get baseWalkSpeed():Number
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[animalId];
			return animalInfo.speed / 10;
		}
		
		public function walkSlow():void
		{
			walkSpeed = baseWalkSpeed / 2;
		}
		
		public function stopWalk():void
		{
			if (walkTimer != null)
			{
				walkTimer.stop();
				walkTimer.removeEventListener(TimerEvent.TIMER, onWalkTick);
				walkTimer = null;
			}
		}
		
		public function startWalk():void
		{
			if (walkTimer == null)
			{
				//加载时钟
				walkTimer = new Timer(50);
				walkTimer.start();
				walkTimer.addEventListener(TimerEvent.TIMER, onWalkTick);
			}
//			if (Math.random() < 0.5)
//				walkSpeed = baseWalkSpeed;
//			else
//				walkSpeed = -baseWalkSpeed;
		}
		
		//wordKind = 3表示胜利时候说的话 wordKind = 4表示失败时候说的话
		public function speak(metaIndex:int, delay:Number = 0, messageIndex:int = -1):void 
		{
			var content:String = Config.languageConfig.getLanguage(metaIndex, messageIndex);
			speak2(content, delay); 
		}
		
		public function speak2(content:String, delay:Number = 0):void
		{
			if (!this.speakFlag)
			{
				speakFlag = true;
				TweenLite.delayedCall(delay, startSpeak, [content]);
			}
		}

		private function startSpeak(content:String):void
		{
			speakFlag = true;
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			var ClueMsgBgrImage:Class = ResourceHelper.getInstance().getClassByName("DialogMsgBgrImage");
			speakMsgBgrSprite = new ClueMsgBgrImage();
			speakMsgBgrSprite.width = 180;
			speakMsgBgrSprite.height = 100;
			speakMsgBgrSprite.mouseEnabled = false;
			speakMsgBgrSprite.mouseChildren = false;
			if (!this.leftFlag)
			{
				speakMsgBgrSprite.scaleX = -1;
			}
			fight.addChild(speakMsgBgrSprite);
			speakMsgText = new TextField();
			speakMsgText.selectable = false;
			speakMsgText.mouseEnabled = false;
        	speakMsgText.autoSize = TextFieldAutoSize.LEFT;
        	speakMsgText.wordWrap = true;
        	speakMsgText.width = speakMsgBgrSprite.width * 0.8;
        	speakMsgText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000);
        	speakMsgText.text = content;
			updateSpeakMsgPosition();
			fight.addChild(speakMsgText);
			TweenLite.delayedCall(3, closeSpeak);
		}
		
		private function closeSpeak():void
		{
			speakFlag = false
			if (speakMsgText != null && speakMsgText.parent != null)
			{
				speakMsgText.parent.removeChild(speakMsgText);
			}
			if (speakMsgBgrSprite != null && speakMsgBgrSprite.parent != null)
			{
				speakMsgBgrSprite.parent.removeChild(speakMsgBgrSprite);
			}
		}
		
		//完全随机选择骨头
		private function randSelectBoneIndex():int
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[animalId];
			var player:PlayerInfo = PlayerInfoHelper.getInstance().players[animalInfo.ownerId];
			var packageBones:Array = new Array();
			for (var indexStr:String in player.userPackage.objectList)
			{
				var index:int = parseInt(indexStr);
				var objectConfig:ObjectConfig = Config.objectConfigs[index];
				//只能扔骨头（排除索引号为1的金骨头，基本骨头无限）
				if (objectConfig.type == 0 && (index == 0 || index != 1 && player.userPackage.objectList[index] > 0) && objectConfig.splitBoneNum != 3)
				{
					//如果自身还在加血中，就不扔加血骨头
					if (!(objectConfig.effects[3] != null && bloodGainEffectCoolDown > 0))
						packageBones.push(index);
				}
			}
			var i:int = Math.random() * packageBones.length;
			return packageBones[i];
		}
		
		//设置准备的骨头		
		public function setPreparedBone(boneIndex:int):void
		{
			this.preparedBoneIndex = boneIndex;
		}
		
		//随机改变准备扔的骨头
		public function changePreparedBone():void
		{
			setPreparedBone(randSelectBoneIndex());
			//新手引导时只使用最基本的弓
			if (leftFlag && SceneContainer.getInstance().step > 0)
			{
				getOnLauncher(32);
			}
			else
			{
				var launcherIndex:int = getMaxVitalityLauncher();
				getOnLauncher(launcherIndex);
			}
		}
		
		//得到最好的弓
		public function getMaxVitalityLauncher():int
		{
			var launcherVitalityMax:int = 0;
			var launcherIndex:int = 32;
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[animalId];
			var player:PlayerInfo = PlayerInfoHelper.getInstance().players[animalInfo.ownerId];
			for (var indexStr:String in player.userPackage.objectList)
			{
				var objectIndex:int = parseInt(indexStr);
				var objectConfig:ObjectConfig = Config.objectConfigs[objectIndex];
				//遍历所有的弓
				if (objectConfig.type == 3 && player.userPackage.objectList[objectIndex] > 0)
				{
					var launcherConfig:LauncherConfig = objectConfig as LauncherConfig;
					if (launcherConfig.vitalityMax > launcherVitalityMax)
					{
						launcherVitalityMax = launcherConfig.vitalityMax;
						launcherIndex = objectIndex;
					}
				}
			}
			return launcherIndex;
		}
		
		//扔出准备好的骨头（托管）
		public function throwPreparedBone():void
		{
			this.makeDecisionToMove();
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			if (animalInfo.vitalityPoint <= 0)
				return;
			var boneConfig:ObjectConfig = Config.objectConfigs[this.preparedBoneIndex];
			//弓箭准备骨头
			launcher.prepareBone(preparedBoneIndex);
			var vitality:Number;
			//加血的骨头
			if (boneConfig.effects[3] != null)
			{
				launcher.rotation = 180;
				vitality = 1;
			}
			else
			{
				//设置角度
				var rotationLimit1:Number = 10;
				var rotationLimit2:Number = 85;
				if (leftFlag)
					launcher.rotation = b2Math.RandomRange(rotationLimit1, rotationLimit2);
				else
					launcher.rotation = -b2Math.RandomRange(rotationLimit1, rotationLimit2);
				//计算合适的体力
				vitality = b2Math.RandomRange(boneConfig.weight * 3, boneConfig.weight * 5);
			}
			//设置体力
			vitality = Math.min(vitality, animalInfo.vitalityPoint);
			launcher.setBoneByVitality(vitality);
			//发射
			var vitalityUsed:Number = launcher.launchPrepareBone();
			//消耗体力
			if (this.leftFlag && SceneContainer.getInstance().step > 5)
				return;
			vitalityChange(-vitalityUsed);
			//消耗物品
			consumeObject(preparedBoneIndex);
		}
		
		public function consumeObject(objectIndex:int):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			var ownerInfo:PlayerInfo = PlayerInfoHelper.getInstance().players[animalInfo.ownerId];
			ownerInfo.userPackage.objectList[objectIndex]--;
			if (consumedObjects[objectIndex] == null)
			{
				consumedObjects[objectIndex] = 1;
			}
			else
			{
				consumedObjects[objectIndex]++;
			}
		}
		
		//根据智力是否移动
		public function makeDecisionToMove(target:int = -1):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			if (target != -1)
			{
				this.moveTarget = target;
			}
			else if (Math.random() < 0.8 && this.x == this.moveTarget)
			{
				if (Math.random() < 0.5)
				{
				 	this.moveTarget = this.x + 140;
				}
				else 
				{
					this.moveTarget = this.x - 140;
				}
			}
			if (this.leftFlag && this.moveTarget < 20) this.moveTarget = 20;
			else if (this.leftFlag && this.moveTarget > fight.stone.x - this.animalMc.width - 20) this.moveTarget = fight.stone.x - this.animalMc.width - 20;
			else if (!this.leftFlag && this.moveTarget > 780 - this.animalMc.width ) this.moveTarget = 780 - this.animalMc.width ;
			else if (!this.leftFlag && this.moveTarget < fight.stone.x + fight.stone.width + 20) this.moveTarget = fight.stone.x + fight.stone.width + 20;
		}
		
		//是否换骨头
		public function makeDecision():void
		{
			var boneConfig:ObjectConfig = Config.objectConfigs[preparedBoneIndex];
			if (boneConfig.effects[3] != null || Math.random() < 0.3)
			{
				changePreparedBone();
			}
		}
		
		//进度条到右侧时的响应函数
		public virtual function onAction():void
		{
			//动物透明度变化
			if (transparentEffectCoolDown > 0)
			{
				if (--transparentEffectCoolDown <= 0)
					stopTransparent();
			}
			//动物大小改变
			if (changeSizeEffectCoolDown > 0)
			{
				if (--changeSizeEffectCoolDown <= 0)
					stopChangeSize();
			}
			//每回合流血
			if (bloodDropEffectCoolDown > 0)
			{
				dropBlood();
				if (--bloodDropEffectCoolDown <= 0)
					stopDropBlood();
			}
			//每回合加血
			if (bloodGainEffectCoolDown > 0)
			{
				gainBlood();
				if (--bloodGainEffectCoolDown <= 0)
					stopGainBlood();
			}
			//动物停止移动 
			if (cageEffectCoolDown > 0)
			{
				if (--cageEffectCoolDown <= 0)
					stopCage();
			}
			//封魔持续时间.
			if (this.allStatus[2] != null)
			{
				var forbidStatus:AnimalStatus = this.allStatus[2] as AnimalStatus;
				if (forbidStatus.coolDownTime >= 0)
				{
					forbidStatus.coolDownTime --;
				}
			}
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[animalId];
			//魔法冷却回合更新
			var virtualAnimalConfig:VirtualAnimalConfig = animalInfo as VirtualAnimalConfig;
			//虚拟动物
			if (virtualAnimalConfig != null)
			{
				for (var magicIndex:String in virtualAnimalConfig.ownMagic)
				{
					var magicLevel:int = virtualAnimalConfig.ownMagic[magicIndex];
					var magicConfig:MagicConfig = Config.magicConfigs[magicIndex];
					if (animalInfo.cooldown[magicIndex] != null)
					{
						if (animalInfo.cooldown[magicIndex] > 0)
							animalInfo.cooldown[magicIndex]--;
					}
					else
						animalInfo.cooldown[magicIndex] = magicConfig.cooldown[magicLevel];
				}
			}
			else
			{
				for (var position:String in animalInfo.equips)
				{
					var equipInfo:EquipInfo = animalInfo.equips[position];
					var equipConfig:EquipConfig = Config.objectConfigs[equipInfo.objectIndex];
					magicConfig = Config.magicConfigs[equipConfig.magicIndex];
					if (animalInfo.cooldown[equipConfig.magicIndex] != null)
					{
						if (animalInfo.cooldown[equipConfig.magicIndex] > 0)
							animalInfo.cooldown[equipConfig.magicIndex]--;
					}
					else
						animalInfo.cooldown[equipConfig.magicIndex] = magicConfig.cooldown[equipConfig.color];
				}
				var wholeEquipConfig:EquipConfig = animalInfo.getWholeEquipConfig();
				if (wholeEquipConfig != null)
				{
					magicConfig = Config.magicConfigs[wholeEquipConfig.wholeMagicIndex];
					if (animalInfo.cooldown[wholeEquipConfig.wholeMagicIndex] != null)
					{
						if (animalInfo.cooldown[wholeEquipConfig.wholeMagicIndex] > 0)
							animalInfo.cooldown[wholeEquipConfig.wholeMagicIndex]--;
					}
					else
						animalInfo.cooldown[wholeEquipConfig.wholeMagicIndex] = magicConfig.cooldown[wholeEquipConfig.color];
				}
			}
			if (animalInfo.vitalityPoint > 0)
			{
				//不托管
				if (leftFlag && !fight.managedIcon.managedFlag)
				{
					fight.pauseGame();			
					var ownerInfo:PlayerInfo = PlayerInfoHelper.getInstance().players[animalInfo.ownerId];	
					if (ownerInfo.userPackage.objectList[preparedBoneIndex] <= 0)
					{
						changePreparedBone();
					}
					launcher.prepareBone(this.preparedBoneIndex);
					var magicPane:MagicPane = MagicPane.getInstance();
					if (this.allStatus[2] != null)
					{
						magicPane.refresh(animalId, (this.allStatus[2] as AnimalStatus).coolDownTime);
					}
					else
					{
						magicPane.refresh(animalId);
					}
					var paneWidth:int = Math.min(magicPane.iconCount, magicPane.iconNumInRow) * 70;
					magicPane.x = 220 - paneWidth / 2;
					magicPane.y = 240;
					fight.controlLayer.addChild(magicPane);
					if (SceneContainer.getInstance().step == 16 || SceneContainer.getInstance().step == 18 || SceneContainer.getInstance().step == 19 ||
						SceneContainer.getInstance().step == 20 || SceneContainer.getInstance().step == 21 || SceneContainer.getInstance().step == 22)
					{
						SceneContainer.getInstance().addStep();
					}
				}
				//托管
				else
				{
					actionByBobot();
				}
			}
		}
		
		//托管时的行动
		public function actionByBobot():void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[animalId];
			var actionFlag:Boolean = false;
			//选择魔法
			var virtualAnimalConfig:VirtualAnimalConfig = animalInfo as VirtualAnimalConfig;
			//虚拟动物
			if (virtualAnimalConfig != null)
			{
				for (var magicIndex:String in virtualAnimalConfig.ownMagic)
				{
					var magicLevel:int = virtualAnimalConfig.ownMagic[magicIndex];
					var magicConfig:MagicConfig = Config.magicConfigs[magicIndex];
					if (magicConfig.vitalityCost[magicLevel] <= animalInfo.vitalityPoint && 
						animalInfo.cooldown[magicIndex] != null && animalInfo.cooldown[magicIndex] <= 0)
					{
						if (this.allStatus[2] != null && (this.allStatus[2] as AnimalStatus).coolDownTime >= 0)
						{
							if (Math.random() < 0.5)
							{
								useMagic(magicConfig.index, magicLevel);
								actionFlag = true;
								break;
							}
						}
					}
				}
			}
			else
			{
				//装备整体魔法
				var wholeEquipConfig:EquipConfig = animalInfo.getWholeEquipConfig();
				if (wholeEquipConfig != null)
				{
					magicConfig = Config.magicConfigs[wholeEquipConfig.wholeMagicIndex];
					if (magicConfig.vitalityCost[wholeEquipConfig.color] <= animalInfo.vitalityPoint && animalInfo.cooldown[wholeEquipConfig.wholeMagicIndex] == 0)
					{
						if (this.allStatus[2] != null && (this.allStatus[2] as AnimalStatus).coolDownTime < 0)
						{
							if (Math.random() < 0.9)
							{
								useMagic(wholeEquipConfig.wholeMagicIndex, wholeEquipConfig.color);
								actionFlag = true;
							}
						}
					} 
				}
				if (!actionFlag)
				{
					for (var position:String in animalInfo.equips)
					{
						var equipInfo:EquipInfo = animalInfo.equips[position];
						var equipConfig:EquipConfig = Config.objectConfigs[equipInfo.objectIndex];
						magicConfig = Config.magicConfigs[equipConfig.magicIndex];
						if (magicConfig.vitalityCost[equipConfig.color] <= animalInfo.vitalityPoint && 
							animalInfo.cooldown[equipConfig.magicIndex] != null && animalInfo.cooldown[equipConfig.magicIndex] <= 0)
						{
							if (this.allStatus[2] != null && (this.allStatus[2] as AnimalStatus).coolDownTime >= 0)
							{
								if (Math.random() < 0.5)
								{
									useMagic(equipConfig.magicIndex, equipConfig.color);
									actionFlag = true;
									break;
								}
							}
						}
					}
				}
			}
			if (!actionFlag)
			{
				//选择物理攻击
				var boneConfig:ObjectConfig = Config.objectConfigs[preparedBoneIndex];
				if (boneConfig.effects[3] != null || Math.random() < 0.3)
				{
					changePreparedBone();
				}
				throwPreparedBone();
				var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
				fight.resumeGame();
			}
		}
		
		//时钟
		private function onTick(event:TimerEvent):void
		{
			for (var statusIndex:String in this.allStatus)
			{
				var status:AnimalStatus = this.allStatus[statusIndex];
				if (status.hPChangeIteration > 0)
				{
					healthChange(status.hPChange);
					status.hPChangeIteration--;
				}
				if (status.vPChangeIteration > 0)
				{
					vitalityChange(status.vPChange);
					status.vPChangeIteration--;
				}
			}
		}
		
		//动物移动
		public function onWalkTick(event:TimerEvent):void
		{
			//新手引导时不动
			if (SceneContainer.getInstance().step > 0)
				return;
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId]
			if (animalInfo.healthPoint <= 0)
				return;
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			//判断范围
			if (leftFlag)
				animalMc.status = 2;
			else
				animalMc.status = 1;
			if (this.moveTarget - this.x > walkSpeed)
			{
				setPosition(this.x + walkSpeed, this.y);
			}
			else if (this.moveTarget - this.x < -walkSpeed)
			{
				setPosition(this.x - walkSpeed, this.y);
			}
			else
			{
				setPosition(this.moveTarget, this.y);
//				this.stopWalk();
			}
			updateSpeakMsgPosition();
			
		}
		
		//设置动物说的话的显示位置
		public function updateSpeakMsgPosition():void
		{
			if (null != speakMsgBgrSprite)
			{
				speakMsgBgrSprite.x = this.x + 10;
				speakMsgBgrSprite.y = this.y - speakMsgBgrSprite.height - this.animalMc.animalHeight;
				speakMsgText.x = speakMsgBgrSprite.x + 20 ;
				speakMsgText.y = speakMsgBgrSprite.y + speakMsgBgrSprite.height * 0.15;
				if (!this.leftFlag)
				{
					speakMsgText.x -= speakMsgBgrSprite.width;
				}
			}
			
		}
		
		//动物的热点初始化
		public function initialAnimalHitPoints():void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			var animalConfig:AnimalConfig = Config.animalConfigs[animalInfo.animalIndex];
			hitPoints = new Array();
			for (var clueIndex:String in  animalConfig.animalClues)
			{
				var animalClue:AnimalClueConfig = animalConfig.animalClues[clueIndex];
				for (var i:int = 0; i < animalClue.hitPoints.length; i++)
				{
					hitPoints.push(animalClue.hitPoints[i]);	
				}
			}
		}
		
		//使用药剂
		public function usePotion(armIndex:int):void
		{   
			var armConfig:ObjectConfig = Config.objectConfigs[armIndex];
			if (armConfig.effects[24] != null)
			{
				var targeScale:Number = armConfig.bonusData1;
				var coolDownRoundNum:int = armConfig.bonusData2;
				startChangeSize(targeScale, coolDownRoundNum);
			}
			else if (armConfig.effects[26] != null)
			{
				startTransparent(0.4, armConfig.bonusData1);
			}
		}
		
		//开始加血（月饼作用）
		public function startGainBlood(healthPointGain:int, coolDownRoundNum:int):void
		{
			var yellowColorMat:ColorMatrixFilter = new ColorMatrixFilter(BFont.yellowFilter);
			this.animalMc.filters = [yellowColorMat];
			this.progressBar.addIconFilter(BFont.yellowFilter);
			this.bloodGainEffectCoolDown = coolDownRoundNum;
			this.healthPointGain = healthPointGain;
			this.gainBlood();
		}
		
		//停止加血
		public function stopGainBlood():void
		{
			this.bloodDropEffectCoolDown == 0;
			this.animalMc.filters = null;
			this.progressBar.removeIconFilters();
			if (dropBloodImg != null && dropBloodImg.parent != null)
			{
				dropBloodImg.parent.removeChild(dropBloodImg);
			}
		}
		
		//开始流血（骨刺作用）
		public function startDropBlood(healthPointDrop:int, coolDownRoundNum:int):void
		{
			//如果目前没有流血
			if (this.bloodDropEffectCoolDown <= 0)
			{
				var redColorMat:ColorMatrixFilter = new ColorMatrixFilter(BFont.redFilter);
				this.animalMc.filters = [redColorMat];
				this.progressBar.addIconFilter(BFont.redFilter);
				var ExtraBlood:Class = ResourceHelper.getInstance().getClassByName("ExtraBlood");
				dropBloodImg = new ExtraBlood();
				dropBloodImg.width = 10;
				dropBloodImg.scaleY = dropBloodImg.scaleX;
				dropBloodImg.x = this.animalMc.x;
				dropBloodImg.y = this.animalMc.height;
				addChild(dropBloodImg);
				dropBloodImg.mouseEnabled = false;
			}
			this.bloodDropEffectCoolDown = coolDownRoundNum;
			this.healthPointDrop = healthPointDrop;
			this.dropBlood();
		}
		
		//停止流血
		public function stopDropBlood():void
		{
			this.bloodDropEffectCoolDown == 0;
			this.animalMc.filters = null;
			this.progressBar.removeIconFilters();
			if (dropBloodImg != null && dropBloodImg.parent != null)
			{
				dropBloodImg.parent.removeChild(dropBloodImg);
			}
		}
		
		//动物隐形
		public function startTransparent(alpha:Number, coolDownRoundNum:int):void
		{
			this.alpha = alpha;
			this.transparentEffectCoolDown = coolDownRoundNum;
			this.destroyB2Body();
		}
		
		//动物是否停止透明
		public function stopTransparent():void
		{
			this.alpha = 1;
			this.transparentEffectCoolDown = 0;
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			this.createB2Body(fight.world, this.x, this.y, this.animalMc.animalWidth, this.animalMc.animalHeight, 1, 0, false);
		}
		
		//动物变大变小
		public function startChangeSize(targetScale:Number, coolDownRoundNum:int):void
		{
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			TweenLite.to(this, 0.5, {scaleX:targetScale, scaleY:targetScale});
			this.destroyB2Body();
			this.createB2Body(fight.world, this.x, this.y, this.animalMc.animalWidth * targetScale, this.animalMc.animalHeight * targetScale, 1, 0, false);
			this.changeSizeEffectCoolDown = coolDownRoundNum;
		}
		
		//恢复原来的大小
		public function stopChangeSize():void
		{
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			TweenLite.to(this, 0.5, {scaleX:1, scaleY:1});
			changeSizeEffectCoolDown = 0;
			this.destroyB2Body();
			this.createB2Body(fight.world, this.x, this.y, this.animalMc.animalWidth, this.animalMc.animalHeight, 1, 0, false);
		}
		
		//体力变化
		public function vitalityChange(vitalityPointChange:Number = 0):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			animalInfo.vitalityPoint += vitalityPointChange;
			addVitalityPoint += vitalityPointChange;
			if (vitalityBar != null)
				vitalityBar.changeBar(vitalityPointChange);
		}
		
		//被打飞，上天
		public function flyOut():void
		{
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			this.animalMc.status = 0;
			if (this.leftFlag)
			{
				TweenLite.to(this, 1, {x:50, y:200, scaleX:0, scaleY:0, rotation: -90, onComplete: this.destroy});
			}
			else
			{
				TweenLite.to(this, 1, {x:750, y:200, scaleX:0, scaleY:0, rotation: 90, onComplete: this.destroy});
			}
		}
		
		//血量改变，血条相应变化
		public function healthChange(healthPointChange:int = 0):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			//已死的动物不再改变血量
			if (animalInfo.healthPoint <= 0)
				return;
			animalInfo.healthPoint = animalInfo.healthPoint + healthPointChange;
			addHealhPoint += healthPointChange;
			if (healthBar != null)
				healthBar.changeBar(healthPointChange);
			if (animalInfo.healthPoint <= 0)
				die();
		}
		
		//死亡出局
		public function die():void
		{
			//在新手引导中，取消死亡
			if (SceneContainer.getInstance().step > 0)
				return;
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			animalInfo.healthPoint = 0;
			progressBar.stop();
			//延迟调用去除box2D body
			TweenLite.delayedCall(0.1, destroyB2Body);
			flyOut();
			//判断是否结束战斗
			var animals:Object = PlayerInfoHelper.getInstance().animals;
			var leftSideHealthPointSum:Number = 0;
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			for (var i:int = 0; i < fight.leftAnimalIds.length; i++)
			{
				var leftAnimalInfo:AnimalInfo = animals[fight.leftAnimalIds[i]];
				leftSideHealthPointSum += leftAnimalInfo.healthPoint;
			}
			var rightSideHealthPointSum:Number = 0;
			for (i = 0; i < fight.rightAnimalIds.length; i++)
			{
				var rightAnimalInfo:AnimalInfo = animals[fight.rightAnimalIds[i]];
				rightSideHealthPointSum += rightAnimalInfo.healthPoint;
			}
			if (leftSideHealthPointSum <= 0 || rightSideHealthPointSum <= 0)
			{
				TweenLite.delayedCall(1.5, fight.endGame);
			}
		}
		
		//让所有进度条继续
		public function allResume():void
		{
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			for (var i:int = 0; i < fight.animals.length; i++)
			{
				var animal:Animal = fight.animals[i];
				animal.progressBar.resume();
			}
		}
		
		//动物不同热点的动画
		public function animalMcReaction(type:int):void
		{
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			if (type != 0 && animalInfo.healthPoint > 0)
			{
				this.animalMc.status = type;
			}
		}

		//动物掉落线索或装备
		public function clueOrArmDrop(hitPoint:HotPoint):void
		{
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			//虚拟动物
			if (fight.rightAnimal.animalId < 0)
			{
				var virtualAnimalConfig:VirtualAnimalConfig = animalInfo as VirtualAnimalConfig;
				if (virtualAnimalConfig != null)
				{
					for (var armIndex:String in virtualAnimalConfig.armsDropPossibility)
					{
						if (null == bossEquipDrop[armIndex] && Math.random() < virtualAnimalConfig.armsDropPossibility[armIndex])
						{
							bossEquipDrop[armIndex] = 1;
							//加入动画
							var animalArmMc:ArmDropMc = new ArmDropMc(parseInt(armIndex), 0);
							animalArmMc.x = this.x + this.animalMc.x;
							animalArmMc.y = this.y + this.animalMc.y;
							this.parent.addChild(animalArmMc);
							animalArmMc.move();
						}
					}
				}
			}
			//左侧的真实用户
			else if (this.leftFlag && this.animalId > 0)
			{
				if (Math.random() < hitPoint.dropPossibility)
				{
					var clueInfo:ClueInfo = new ClueInfo();
					clueInfo.clueIndex = hitPoint.clueIndex;
					var clueConfig:ClueConfig = Config.clueConfigs[clueInfo.clueIndex];
					clueInfo.clueValue = animalInfo.animalClues[clueInfo.clueIndex];;
					clueInfo.timeToDisappear = ServerHelper.getInstance().now() + clueConfig.timeToDisappear;
					clueInfo.jawType = (Config.animalConfigs[animalInfo.animalIndex] as AnimalConfig).camp;
					//不重复掉落线索
					if (null == animalCluesDrop[clueInfo.clueIndex])
					{
						//每种线索只有一个值
						this.animalCluesDrop[clueInfo.clueIndex] = clueInfo;
						//加入动画
						var animalClueMc:ClueMc = new ClueMc(clueInfo);
						animalClueMc.x = this.x + this.animalMc.x;
						animalClueMc.y = this.y + this.animalMc.y;
						this.parent.addChild(animalClueMc);
						animalClueMc.move();
					}
				}
			}
		}
		
		//被骨头击中后的所有响应
		public function hitByBone(bone:Bone, hitPoint:HotPoint = null, damage:Number = 0):void
		{
			this.makeDecisionToMove();
			var boneConfig:ObjectConfig = Config.objectConfigs[bone.index];
			//骨牢消失
			if (boneConfig.effects[6] != null)
				TweenLite.delayedCall(0.1, bone.destroy);
			//加血效果时不减血
			if (boneConfig.effects[3] == null)
				healthChange(-damage);
			animalReaction(boneConfig);
			animalMcReaction(hitPoint.animalReactionType);
			if (hitPoint != null)
			{
				clueOrArmDrop(hitPoint);
			}
		}
		
		//被击中后可能会移动
		
		
		//动物被不同骨头碰撞后的反应（流血，速度）
		public function animalReaction(boneConfig:ObjectConfig):void
		{
			if (Math.random() < Config.speakProbability)
			{
				speak(5);
			}
			for (var effectIndex:String in boneConfig.effects)
			{
				var bonusData1:int = boneConfig.bonusData1;
				var bonusData2:int = boneConfig.bonusData2;
				switch (boneConfig.effects[effectIndex])
				{
					//眩晕（骨锤）
					case 1:
						this.startDizzy(bonusData1);
						break;
					//流血作用（骨刺）
					case 2:
						this.startDropBlood(bonusData1, bonusData2);
						break;
					//加血作用（月饼）
					case 3:
						this.startGainBlood(bonusData1, bonusData2);
						break;
					//冰冻减速（冰骨）
					case 4:
						this.startSlow(bonusData1, bonusData2);
						break;
					//骨牢
					case 6:
						this.startCage(bonusData1);
						break;
				}
			}
		}
		
		//动物晕
		public function startDizzy(timeOfStop:int):void
		{
			if (timeToStopDizzy <= 0)
			{
				var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
				var AnimalDizzy:Class = ResourceHelper.getInstance().getClassByName("AnimalDizzy");
				animalDizzyMc = new BasicMc(AnimalDizzy, 60);
				addChild(animalDizzyMc);
				animalDizzyMc.mouseEnabled = false;
				animalDizzyMc.x = this.animalMc.x - 10;
				animalDizzyMc.y = -this.animalMc.animalHeight - 20;
				this.stopWalk();
				this.progressBar.addIconDizzyMc(animalInfo.animalIndex);
			}
			this.timeToStopDizzy = ServerHelper.getInstance().now() + timeOfStop;
		}
		
		//动物停止晕
		public function stopDizzy():void
		{
			if (animalDizzyMc != null && animalDizzyMc.parent != null)
				animalDizzyMc.parent.removeChild(animalDizzyMc);
			this.timeToStopDizzy = 0;
			this.progressBar.removeIconDizzyMc();
		}
	
		//动物流血
		public function dropBlood():void  
		{
			if (this.leftFlag)
			{
				dropBloodImg.x = this.animalMc.x + this.animalMc.animalWidth / 2;
			}
			else
			{
				dropBloodImg.x = this.animalMc.x - this.animalMc.animalWidth / 2;
			}
			dropBloodImg.y = this.animalMc.y - this.animalMc.animalHeight;
			this.healthChange(-healthPointDrop);
			this.dropBloodImg.visible = true;
			TweenLite.to(dropBloodImg, 0.5, {x: this.animalMc.x - 10, y: 60 + this.animalMc.y + this.animalMc.animalHeight, onComplete:resetDropBloodPosition});
		}
		
		//动物加血
		public function gainBlood():void  
		{
			var PlusImage:Class = ResourceHelper.getInstance().getClassByName("PlusImage");
			var gainBloodImg:Sprite = new PlusImage();
			gainBloodImg.width = 10;
			gainBloodImg.scaleY = gainBloodImg.scaleX;
			gainBloodImg.y = -this.animalMc.height - 5;
			addChild(gainBloodImg);
			gainBloodImg.mouseEnabled = false;
			this.healthChange(this.healthPointGain);
			TweenLite.to(gainBloodImg, 0.3, {x: -20, y: -this.animalMc.animalHeight - 105, scaleX:1, scaleY:1, onComplete:resetGainBloodPosition, onCompleteParams:[gainBloodImg]});
		}
		
		//重新设置流血图片位置
		public function resetDropBloodPosition():void
		{
			dropBloodImg.visible = false;
		}
		
		//重新设置加血图片位置
		public function resetGainBloodPosition(gainBloodImg:Sprite):void
		{
			if (gainBloodImg != null && gainBloodImg.parent != null)
				gainBloodImg.parent.removeChild(gainBloodImg);
		}
		
		//动物冰冻
		public function startSlow(speedOfSlow:Number, timeOfSlow:int):void
		{
			if (timeToStopSlow <= 0)
			{
				this.speedBeforeSlow = this.progressBar.getSpeed();
				var speed:Number = this.speedBeforeSlow * (1 - speedOfSlow);
				var greenColorMat:ColorMatrixFilter = new ColorMatrixFilter(BFont.greenFilter);
				this.animalMc.filters = [greenColorMat];
				this.walkSlow();
				var Ice:Class = ResourceHelper.getInstance().getClassByName("Ice3");
				iceImg = new Ice();
				iceImg.height = this.animalMc.animalHeight;
				iceImg.width = this.animalMc.animalWidth + 30;
				iceImg.alpha = 0.3;
				iceImg.x = this.animalMc.x - this.animalMc.animalWidth / 2 - 15;
				iceImg.y = this.animalMc.y - this.animalMc.animalHeight;
				addChild(iceImg);
				iceImg.mouseEnabled = false;
				this.progressBar.setSpeed(speed);
				this.progressBar.addIconFilter(BFont.blueFilter);
				var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
				this.progressBar.addIconIce(animalInfo.animalIndex, iceImg.alpha);
			}
			this.timeToStopSlow = ServerHelper.getInstance().now() + timeOfSlow;
		}
		
		//动物停止冰冻
		public function stopSlow():void
		{
			this.timeToStopSlow = 0;
			this.animalMc.filters = null;
			this.walkSpeed = this.baseWalkSpeed;
			removeChild(iceImg);
			this.progressBar.setSpeed(speedBeforeSlow);
			this.progressBar.removeIconFilters();
			this.progressBar.removeIconIce();
		}
		
		//动物被骨牢关住
		public function startCage(coolDownRoundNum:int):void
		{
			if (this.cageEffectCoolDown <= 0)
			{
				var Cage:Class = ResourceHelper.getInstance().getClassByName("Bone6");//Cage
				cageImg = new Cage();
				cageImg.width = this.animalMc.animalWidth + 10;
				cageImg.height = this.animalMc.animalHeight + 10;
				cageImg.x = this.animalMc.x - cageImg.width / 2;
				cageImg.y = this.animalMc.y - cageImg.height;
				addChild(cageImg);
				cageImg.mouseEnabled = false;
			}
			this.cageEffectCoolDown = coolDownRoundNum;
			this.walkSpeed = 0;
		}
	
		//动物停止被骨牢关住
		public function stopCage():void
		{
			if (null != cageImg && cageImg.parent != null)
			{
				cageImg.parent.removeChild(cageImg);
			}
			this.cageEffectCoolDown = 0;
			this.walkSpeed = this.baseWalkSpeed;
		}
		
		//使用魔法
		public function useMagic(magicIndex:int, magicLevel:int):void
		{
			var magicConfig:MagicConfig = Config.magicConfigs[magicIndex];
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			animalInfo.cooldown[magicIndex] = magicConfig.cooldown[magicLevel] + 1;
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			if (magicConfig.skyColor == "dark")
				fight.changeColor(BFont.blackWhiteFilter, BFont.darkFilter);
			else if (magicConfig.skyColor == "red")
				fight.changeColor(BFont.redFilter);
			fight.pauseGame();
			var vitalityCost:int = magicConfig.vitalityCost[magicLevel]
			if (SceneContainer.getInstance().step > 0)
				vitalityCost = vitalityCost / 10;
			this.vitalityChange(-vitalityCost);
			TweenLite.delayedCall(magicConfig.selfMovieDelay, startMagicMovie, [magicConfig.selfMovie, magicConfig.selfMovieFps, 
				magicConfig.selfMoviePosX, magicConfig.selfMoviePosY, magicConfig.selfMovieWidth, magicConfig.selfMovieHeight, magicConfig.selfMovieAlpha]);
			var targetAnimal:Animal;
			if (this.leftFlag)
			{
				targetAnimal = fight.rightAnimal;
			}
			else
			{
				targetAnimal = fight.leftAnimal;
			}
			TweenLite.delayedCall(magicConfig.targetMovieDelay, targetAnimal.startMagicMovie, [magicConfig.targetMovie, magicConfig.targetMovieFps, 
				magicConfig.targetMoviePosX, magicConfig.targetMoviePosY, magicConfig.targetMovieWidth, magicConfig.targetMovieHeight, magicConfig.targetMovieAlpha]);
			//设置状态
			var status:AnimalStatus = new AnimalStatus();
			if (magicConfig.selfStatusIndex > 0)
			{
				status.index = magicConfig.selfStatusIndex;
				status.hPChange = magicConfig.selfStatusHpChange[magicLevel];
				status.hPChangeIteration = magicConfig.selfStatusHpChangeIteration[magicLevel];
				status.coolDownTime = magicConfig.statusCoolDownTime;
				TweenLite.delayedCall(magicConfig.selfStatusDelay, addStatus, [status]);
			}
			if (magicConfig.targetStatusIndex > 0)
			{
				status = new AnimalStatus();
				status.index = magicConfig.targetStatusIndex;
				status.hPChange = magicConfig.targetStatusHpChange[magicLevel];
				status.hPChangeIteration = magicConfig.targetStatusHpChangeIteration[magicLevel];
				status.vPChange = magicConfig.targetStatusVpChange[magicLevel];
				status.vPChangeIteration = magicConfig.targetStatusVpChangeIteration[magicLevel];
				status.coolDownTime = magicConfig.statusCoolDownTime;
				TweenLite.delayedCall(magicConfig.targetStatusDelay, targetAnimal.addStatus, [status]);
			}
			//召唤生物
			if (magicConfig.summonAnimalIndex > 0)
			{
				TweenLite.delayedCall(0.1, summonAnimal, [magicIndex, magicLevel]);
			}
			//召唤盾牌
			if (magicConfig.shieldIndex > 0)
			{
				TweenLite.delayedCall(4, summonShield, [magicIndex, magicLevel]);
			}
		}
		
		//召唤动物
		public function summonAnimal(magicIndex:int, magicLevel:int):void
		{
			var magicConfig:MagicConfig = Config.magicConfigs[magicIndex];
			var animalInfo:AnimalInfo = PlayerInfoHelper.getInstance().animals[this.animalId];
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			//定义变量（使Flash编译此类）
			var crow:Crow;
			var frog:Frog;
			var summonedAnimalInfo:AnimalInfo = new AnimalInfo();
			var summonedAnimalConfig:AnimalConfig = Config.animalConfigs[magicConfig.summonAnimalIndex];
			var hp:int = magicConfig.summonAnimalHp[magicLevel];
			var vp:int = magicConfig.summonAnimalVp[magicLevel];
			var speed:Number = Math.max(magicConfig.summonAnimalSpeed[magicLevel] + b2Math.RandomRange(-5, 5), 1);
			summonedAnimalInfo.id = -ServerHelper.getInstance().now();
			summonedAnimalInfo.animalIndex = magicConfig.summonAnimalIndex;
			summonedAnimalInfo.healthPoint = hp;
			summonedAnimalInfo.vitalityPoint = vp;
			summonedAnimalInfo.resetParams(hp, vp, speed, 20);
			summonedAnimalInfo.animalName = summonedAnimalConfig.name;
			summonedAnimalInfo.ownerName = animalInfo.ownerName;
			summonedAnimalInfo.userData1 = magicConfig.userData1[magicLevel];
			PlayerInfoHelper.getInstance().animals[summonedAnimalInfo.id] = summonedAnimalInfo;
			var calssName:String = "b1.scenes.fight." + summonedAnimalConfig.animalClass;
			var AnimalClass:Class = getDefinitionByName(calssName) as Class;
			var summonedAnimal:Animal = new AnimalClass(summonedAnimalInfo.id, leftFlag);
			summonedAnimal.addThreeBars(fight, 0, true);
			summonedAnimal.summon(); 
			var animalPosX:Number;
			var animalPosY:Number;
			if (!leftFlag)
			{
				animalPosX = this.x - magicConfig.summonAnimalPosX;
				animalPosY = this.y + magicConfig.summonAnimalPosY;
			}
			else
			{
				animalPosX = this.x + magicConfig.summonAnimalPosX;
				animalPosY = this.y + magicConfig.summonAnimalPosY;
			}
			summonedAnimal.createB2Body(fight.world, animalPosX, animalPosY, summonedAnimal.animalMc.animalWidth, summonedAnimal.animalMc.animalHeight, 1, 0, false);
			TweenLite.delayedCall(magicConfig.summonAnimalDuration[magicLevel], summonedAnimal.unsummon);
			fight.objectLayer.addChild(summonedAnimal);
		}
		
		//召唤盾牌
		public function summonShield(magicIndex:int, magicLevel:int):void
		{
			var magicConfig:MagicConfig = Config.magicConfigs[magicIndex];
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			var shield:Shield = new Shield(magicConfig.shieldIndex, 200, leftFlag, magicConfig.shieldDuration[magicLevel]);
			shield.createB2Body(fight.world, 400, 400, shield.width, shield.height, 1, 0, false);
			TweenLite.from(shield, 1, {alpha:0});
			fight.fightObjects.push(shield);
			fight.objectLayer.addChild(shield);
		}
		
		//增加状态
		public function addStatus(status:AnimalStatus):void
		{
			this.allStatus[status.index] = status;
		}
		
		private function startMagicMovie(movieName:String, magicFps:int, posX:Number, posY:Number, magicWidth:Number, magicHeight:Number, magicAlpha:Number):void
		{
			var MagicClass:Class = ResourceHelper.getInstance().getClassByName(movieName);
			if (MagicClass != null)
			{
				magicMovie = new BasicMc(MagicClass, magicFps, false);
				magicMovie.eventDispatcher.addEventListener(BasicMc.ON_MOVIE_FINISH, onMagicMovieComplete);
				if (!leftFlag)
				{
					magicMovie.x = this.x - posX;
					magicMovie.y = this.y + posY;
					magicMovie.height = magicHeight;
					magicMovie.scaleX = -magicMovie.scaleY;
				}
				else
				{
					magicMovie.x = this.x + posX;
					magicMovie.y = this.y + posY;
					magicMovie.height = magicHeight;
					magicMovie.scaleX = magicMovie.scaleY;
				}
				if (magicAlpha > 0)
					magicMovie.alpha = magicAlpha;
				var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
				fight.magicLayer.addChild(magicMovie);
			}
		}
		
		private function onMagicMovieComplete(event:Event):void
		{
			if (magicMovie != null && magicMovie.parent != null)
			{
				magicMovie.parent.removeChild(magicMovie);
				magicMovie = null;
			}
			var fight:Fight = SceneContainer.getInstance().currentScene as Fight;
			for (var i:int = 0; i < fight.animals.length; i++)
			{
				if ((fight.animals[i] as Animal).magicMovie != null)
					return;				
			}
			fight.restoreColor();
			fight.resumeGame();
		}

		//召唤
		public virtual function summon():void
		{
			animalMc.visible = false;
			var MagicClass:Class = ResourceHelper.getInstance().getClassByName("MagicCloud");
			summonMovie = new BasicMc(MagicClass, 30, false);
			summonMovie.scaleX = 0.2;
			summonMovie.scaleY = summonMovie.scaleX;
			addChild(summonMovie);
			summonMovie.eventDispatcher.addEventListener(BasicMc.ON_MOVIE_FINISH, onSummonMovieComplete);
			TweenLite.delayedCall(4.8, showAnimal);
		}

		private function onSummonMovieComplete(event:Event):void
		{
			if (summonMovie != null && summonMovie.parent != null)
			{
				summonMovie.parent.removeChild(summonMovie);
				summonMovie = null;
			}
		}
		
		private function showAnimal():void
		{
			animalMc.visible = true;
		}
		
		private function hideAnimal():void
		{
			animalMc.visible = false;
		}
		
		//消失
		public virtual function unsummon():void
		{
			var MagicClass:Class = ResourceHelper.getInstance().getClassByName("MagicCloud");
			summonMovie = new BasicMc(MagicClass, 30, false);
			summonMovie.scaleX = 0.2;
			summonMovie.scaleY = summonMovie.scaleX;
			addChild(summonMovie);
			summonMovie.eventDispatcher.addEventListener(BasicMc.ON_MOVIE_FINISH, onSummonMovieComplete);
			TweenLite.delayedCall(4.8, hideAnimal);
		}
		
		public override function destroy():void
		{
			super.destroy();
			if (progressBar != null)
				progressBar.destory();
			stopWalk();
			if (timer != null)
			{
				timer.stop();
				timer.removeEventListener(TimerEvent.TIMER, onTick);
				timer = null;
			}
		}
	}
}